home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Scripts / GotoMapVars.py < prev    next >
Encoding:
Python Source  |  2000-11-16  |  10.4 KB  |  406 lines

  1.  
  2.  
  3. import Bladex
  4. import GameState
  5. import MemPersistence
  6. import BBLib
  7. import string
  8.  
  9.  
  10. class MainCharState(GameState.EntityPersonState):
  11.     "Clase para grabar el estado del jugador"
  12.  
  13.     def __init__(self,ent_name="Player1"):
  14.         import CharStats
  15.         entity=Bladex.GetEntity(ent_name)
  16.  
  17.         if not entity:
  18.             return
  19.  
  20.         import Actions
  21.  
  22.  
  23.         self.Props={}
  24.         self.Props["Life"]=CharStats.GetCharMaxLife(entity.Kind,entity.Level)
  25.         self.Props["Level"]=entity.Level
  26.         self.Props["PartialLevel"]=entity.PartialLevel
  27.         self.Props["Energy"]=entity.Energy
  28.         self.Props["Armor"]=(entity.MeshName,entity.Data.armour_level,entity.Data.armour_prot_factor)
  29.  
  30.         
  31.         GameState.EntityPersonState.__init__(self,entity)
  32.         inv=entity.GetInventory()
  33.         self.Inventory={}
  34.         self.Inventory["Objects"]=[]
  35.         for i in range(inv.nKindObjects):
  36.             for name in Actions.GetListOfObjectsAt(inv,i):
  37.                 self.Inventory["Objects"].append(self.__GetObjAux(name))
  38.  
  39.         self.Inventory["Weapons"]=[]
  40.         for i in range(inv.nWeapons):
  41.             self.Inventory["Weapons"].append(self.__GetObjAux(inv.GetWeapon(i)))
  42.  
  43.         self.Inventory["Shields"]=[]
  44.         for i in range(inv.nShields):
  45.             self.Inventory["Shields"].append(self.__GetObjAux(inv.GetShield(i)))
  46.  
  47.         self.Inventory["Quivers"]=[]
  48.         for i in range(inv.nQuivers):
  49.             self.Inventory["Quivers"].append(self.__GetObjAux(inv.GetQuiver(i)))
  50.  
  51.         self.Inventory["Keys"]=[]
  52.         for i in range(inv.nKeys):
  53.             self.Inventory["Keys"].append(self.__GetObjAux(inv.GetKey(i)))
  54.  
  55.         self.Inventory["SpecialKeys"]=[]
  56.         for i in range(inv.nSpecialKeys):
  57.             self.Inventory["SpecialKeys"].append(self.__GetObjAux(inv.GetSpecialKey(i)))
  58.  
  59.         self.Inventory["Tablets"]=[]
  60.         for i in range(inv.nTablets):
  61.             self.Inventory["Tablets"].append(self.__GetObjAux(inv.GetTablet(i)))
  62.  
  63.         self.Inventory["InvLeft"]=self.__GetObjAux(entity.InvLeft)
  64.         self.Inventory["InvLeft2"]=self.__GetObjAux(entity.InvLeft2)
  65.         #Avoid to carry standard objects to another map( chairs and similars)
  66.         if Actions.IsRightHandWeaponObject(entity.Name)==0:
  67.             print "Not taking right hand object to next map cause it┤s not a weapon!"
  68.             self.Inventory["InvRight"]=None
  69.         else:
  70.             self.Inventory["InvRight"]=self.__GetObjAux(entity.InvRight)
  71.         self.Inventory["InvLeftBack"]=self.__GetObjAux(entity.InvLeftBack)
  72.         self.Inventory["InvRightBack"]=self.__GetObjAux(entity.InvRightBack)
  73.  
  74.  
  75.     def __GetBOD(self,ent_kind):
  76.         RM=BBLib.GetResourceManager()
  77.         for i in range(RM.NResources(BBLib.B_CID_OBJDSCR)):
  78.             if RM.IsResourceLoaded(BBLib.B_CID_OBJDSCR,i):
  79.                 if RM.GetResourceName(BBLib.B_CID_OBJDSCR,i)==ent_kind:
  80.                     return RM.GetResourceFile(BBLib.B_CID_OBJDSCR,i)
  81.         return None
  82.  
  83.     def __GetObjAux(self,obj):
  84.         if not obj:
  85.             return None
  86.         objKind=Bladex.GetEntity(obj).Kind
  87.         return (obj,objKind,self.__GetBOD(objKind))
  88.  
  89.  
  90. ##    def SaveInventory(self,file_name):
  91. ##        f=open('../../Save/'+file_name,'wt')
  92. ##        p=cPickle.Pickler(f)
  93. ##        temp={}
  94. ##        temp["Life"]=self.Props["Life"]
  95. ##        temp["Level"]=self.Props["Level"]
  96. ##        temp["PartialLevel"]=self.Props["PartialLevel"]
  97. ##
  98. ##        p.dump((self.CreationProps,temp,self.Inventory))
  99. ##        f.close()
  100.  
  101.  
  102.     def GetProps(self):
  103.         temp={}
  104.         temp["Life"]=self.Props["Life"]
  105.         temp["Level"]=self.Props["Level"]
  106.         temp["PartialLevel"]=self.Props["PartialLevel"]
  107.         temp["Energy"]=self.Props["Energy"]
  108.         temp["Armor"]=self.Props["Armor"]
  109.  
  110.         return (self.CreationProps,temp,self.Inventory)
  111.  
  112. def CreateEntAux(obj_tuple,obj_kind,props=1):
  113.     import ItemTypes
  114.     obj=Bladex.GetEntity(obj_tuple[0])
  115.     if not obj:
  116.         BBLib.ReadBOD(obj_tuple[2])
  117.         obj=Bladex.CreateEntity(obj_tuple[0],obj_tuple[1],0,0,0,obj_kind)
  118.         if props:
  119.             ItemTypes.ItemDefaultFuncs(obj)
  120.     return obj
  121.  
  122.  
  123. def CreateMainCharWithProps(props):
  124.     CreationProps=props[0]
  125.     Props=props[1]
  126.     Inventory=props[2]
  127.  
  128.     import Basic_Funcs
  129.     import AniSound
  130.     import Reference
  131.     import Sparks
  132.     import Breakings
  133.     import Actions
  134.  
  135.  
  136.     char=Bladex.CreateEntity("Player1",CreationProps["Kind"],0,0,0,"Person")
  137.     char.Data=Basic_Funcs.PlayerPerson(char)
  138.     inv=char.GetInventory()
  139.     AniSound.AsignarSonidosCaballero('Player1')
  140.  
  141.     char.Level=Props["Level"]
  142.     char.PartialLevel=Props["PartialLevel"]
  143.     char.Life=Props["Life"]
  144.     char.Energy=Props["Energy"]
  145.     char.SetMesh(Props["Armor"][0])
  146.     char.Data.armour_level       = Props["Armor"][1]
  147.     char.Data.armour_prot_factor = Props["Armor"][2]
  148.     char.SendTriggerSectorMsgs=1
  149.     
  150.     
  151.  
  152.     for i in Inventory["Objects"]:
  153.         CreateEntAux(i,"Physic")
  154.         Actions.ExtendedTakeObject(inv,i[0])
  155.  
  156.     for i in Inventory["Weapons"]:
  157.         obj=CreateEntAux(i,"Weapon")
  158.         object_flag=Reference.GiveObjectFlag(i[0])
  159.         if object_flag == Reference.OBJ_BOW:
  160.             inv.AddBow(i[0])
  161.         else:
  162.             flag=Reference.GiveWeaponFlag(i[0])
  163.             inv.AddWeapon(i[0],flag)
  164.  
  165.  
  166.     for i in Inventory["Shields"]:
  167.         CreateEntAux(i,"Weapon")
  168.         inv.AddShield(i[0])
  169.  
  170.     for i in Inventory["Quivers"]:
  171.         obj=CreateEntAux(i,"Weapon")        
  172.         inv.AddQuiver(i[0])
  173.  
  174.     for i in Inventory["Keys"]:
  175.         CreateEntAux(i,"Physic",0)
  176.         inv.AddKey(i[0])
  177.  
  178.     for i in Inventory["SpecialKeys"]:
  179.         CreateEntAux(i,"Physic",0)
  180.         inv.AddSpecialKey(i[0])
  181.  
  182.     for i in Inventory["Tablets"]:
  183.         CreateEntAux(i,"Physic",0)
  184.         inv.AddTablet(i[0])
  185.  
  186.     if Inventory["InvLeft"]:
  187.         CreateEntAux(Inventory["InvLeft"],"Physic")
  188.         inv.LinkLeftHand(Inventory["InvLeft"][0])
  189.  
  190.     if Inventory["InvLeft2"]:
  191.         CreateEntAux(Inventory["InvLeft2"],"Physic")
  192.         inv.LinkLeftHand2(Inventory["InvLeft2"][0])
  193.  
  194.     if Inventory["InvRight"]:
  195.         CreateEntAux(Inventory["InvRight"],"Physic")
  196.         inv.LinkRightHand(Inventory["InvRight"][0])
  197.  
  198.     if Inventory["InvRightBack"]:
  199.         CreateEntAux(Inventory["InvRightBack"],"Physic")
  200.         inv.LinkRightBack(Inventory["InvRightBack"][0])
  201.  
  202.     if Inventory["InvLeftBack"]:
  203.         CreateEntAux(Inventory["InvLeftBack"],"Physic")
  204.         inv.LinkLeftBack(Inventory["InvLeftBack"][0])
  205.  
  206.  
  207.  
  208. def RestoreMainCharState(key):
  209.   props=MemPersistence.Get(key)
  210.   if props:
  211.     CreateMainCharWithProps(props)
  212.     return 1
  213.   return 0
  214.  
  215.  
  216.  
  217. def SaveMainCharState(key):
  218.   ent_state=MainCharState('Player1')
  219.   props=ent_state.GetProps()
  220.   MemPersistence.Store(key,props)
  221.  
  222.  
  223.  
  224.  
  225.  
  226. #place in scripts
  227. VisitedMaps        = [ 0,0,0,0,
  228.                     0,0,
  229.                     0,
  230.                     0,
  231.                     0,0,0,0,0,0,0,0,0] # Maintained outside, 2DMAP
  232.  
  233. # Once a Tablet is placed on Ianna's update this array
  234. PlacedTablets    = [0,0,0,0,0,0] # Maintained Outside, 2DMAP
  235.  
  236.  
  237. # TEXT TO BE SAVED PER MAP
  238. MText    = []
  239. BaList    = []
  240. for a in range(17):
  241.     MText.append([])
  242.  
  243. # Formerly picked weapons
  244. PWeapons= []
  245.  
  246. # Formerly picked Items
  247. PItems    = []
  248.  
  249. # NOTES:
  250. # Llamar a esta funcion desde cualquier script de mapa donde se quiera aniadir texto, el formato es:
  251. # 1) primero se incluye "import GotoMapVars" en el comiezo del archivo (junto con los otros imports)
  252. # 2) Donde se haya de escribir el texto se pone:
  253. #        GotoMapVars.MapText(Numero del mapa, "el texto que se quiera.htm")
  254. def MapText(MapNum,MapTex):
  255.     if MapNum == -1:
  256.         BaList.append(MapTex)
  257.     else:
  258.         MText[MapNum - 1].append(MapTex) # Must include the -1 offset to make mappers work easier.
  259.  
  260. # Weapon is a string with the internal name of the weapon
  261. def PickedWeapon(Weapon):
  262.     PWeapons.append(Weapon)
  263.  
  264. # Item is a string with the internal name of the item
  265. def PickedItems(Item):
  266.     PItems.append(Item)
  267.  
  268.  
  269. def Set2DMapValuesAux():
  270.     return [VisitedMaps,PlacedTablets,MText,PWeapons,PItems,BaList]
  271.  
  272.  
  273. def Get2DMapValuesAux(vals):
  274.  
  275.     if vals:
  276.         global VisitedMaps
  277.         global PlacedTablets
  278.         global MText
  279.         global PWeapons
  280.         global PItems
  281.         global BaList
  282.         VisitedMaps=vals[0]
  283.         PlacedTablets=vals[1]
  284.         MText=vals[2]
  285.         PWeapons=vals[3]
  286.         PItems=vals[4]
  287.         BaList=vals[5]
  288.         return 1
  289.  
  290.     return 0
  291.  
  292.  
  293.  
  294.  
  295. def Get2DMapValues():
  296.  
  297.     print "Get2DMapValues()"
  298.     vals=MemPersistence.Get('2DMapValues')
  299.     if vals:
  300.         return Get2DMapValuesAux(vals)
  301.     else:
  302.         print "Get2DMapValues() -> can't find vals."
  303.     return 0
  304.  
  305.  
  306. def GetCarriedTablets():
  307.     a = [0,0,0,0,0,0]
  308.     for i in MemPersistence.Get('MainChar')[2]["Tablets"]:
  309.         a[string.atoi(i[0][len("tablilla")])-1] = 1
  310.  
  311.     return a
  312.  
  313.     
  314. def BeginLevel():
  315.     pj=RestoreMainCharState('MainChar')
  316.     if pj:
  317.         return Get2DMapValues()
  318.     return 0
  319.  
  320.     
  321.  
  322.  
  323. # LEVEL ENDING
  324. LevelNames = [    "barb_m1",        "ragnar_m2",    "dwarf_m3",        "ruins_m4",        "mine_m5",    "labyrinth_m6",    
  325.                 "tomb_m7",        "island_m8",    "orc_m9",        "orlok_m10",    "ice_m11",    "btomb_m12",
  326.                 "desert_m13",    "volcano_m14",    "palace_m15",    "tower_m16",    "chaos_m17"]
  327.  
  328. BackLevelNames = [ "mine_back", "labyrinth_back", "tomb_back", "ice_back", "btomb_back", "desert_back",
  329.                    "palace_back"]
  330.  
  331.  
  332. def StoreCharInfo():
  333.  
  334.     import string
  335.     global VisitedMaps
  336.     global BackLevelNames
  337.     global LevelNames
  338.  
  339.     # Save lists in this file in c memory
  340.     try:
  341.         pname = Bladex.GetCurrentMap()
  342.         name = string.lower(pname)
  343.  
  344.         if (name == "palace_m15"):
  345.             name = "palace_back"
  346.         if not(name in BackLevelNames):
  347.             iIndex = LevelNames.index(name)
  348.         else:
  349.             iIndex = BackLevelNames.index(name)
  350.             VisitedMaps[14] = 1
  351.         Bladex.SetStringValue("LastVisitedMap","M_" + str(iIndex+1))
  352.         VisitedMaps[iIndex] = 1
  353.         print iIndex
  354.         MemPersistence.Store('2DMapValues',Set2DMapValuesAux())
  355.     except Exception,exc:
  356.         print "Exception in StoreCharInfo",exc
  357.         
  358.     SaveMainCharState('MainChar')
  359.  
  360.  
  361. def EndOfLevel():
  362.     
  363.     print "EndOfLevel()"
  364.  
  365.     print "Preparing main char for the travel."
  366.     import Actions
  367.     
  368.     print 'Actions.PutAllInBack("Player1")'
  369.     Actions.PutAllInBack("Player1")
  370.     
  371.     print 'Actions.RemoveAllKeys("Player1")'
  372.     Actions.RemoveAllKeys("Player1")
  373.     
  374.     print 'Actions.RemoveNoTravelObjects( "Player1" )'
  375.     Actions.RemoveNoTravelObjects( "Player1" )
  376.     StoreCharInfo()
  377.  
  378.     if (string.lower(Bladex.GetCurrentMap()) == "tower_m16"):
  379.         Bladex.LoadLevel("Chaos_m17")
  380.     else:        
  381.         Bladex.LoadLevel("2dMap")
  382.  
  383. def CreatePJ_PY():
  384.     global VisitedMaps
  385.     global PlacedTablets
  386.     global MText
  387.     global PWeapons
  388.     global PItems
  389.     global BaList
  390.         
  391.     SaveMainCharState('MainChar')
  392.     
  393.     cfgfile = open("pj.py",'w')
  394.     cfgfile.write("import GotoMapVars\n")
  395.     cfgfile.write("GotoMapVars.VisitedMaps             = "+`VisitedMaps`+'\n')
  396.     cfgfile.write("GotoMapVars.PlacedTablets           = "+`PlacedTablets`+'\n')
  397.     cfgfile.write("GotoMapVars.MText                   = "+`MText`+'\n')    
  398.     cfgfile.write("GotoMapVars.PWeapons                = "+`PWeapons`+'\n')
  399.     cfgfile.write("GotoMapVars.PItems                  = "+`PItems`+'\n')
  400.     cfgfile.write("GotoMapVars.BaList                  = "+`BaList`+'\n')
  401.     
  402.     cfgfile.write("charprops = "+`MemPersistence.Get('MainChar')`+'\n')
  403.     cfgfile.write("GotoMapVars.CreateMainCharWithProps(charprops)"+'\n')
  404.     
  405.  
  406.     cfgfile.close()